<?php
header('Content-Type:text/html;charset=utf-8');

class Survey extends CI_Controller {
	public function index()
	{
		$this->load->view('survey');
	}
	
	function insert()
	{
		//插入db
		if ( $_POST['name'] == '' ):
			echo '<script type="text/javascript" language="javascript" charset="utf-8">alert("请填写姓名");history.back();</script>';
		elseif ( $_POST['phone'] == '' ):
			echo '<script type="text/javascript" language="javascript" charset="utf-8">alert("请填写电话");history.back();</script>';
		else:
			if ( $_POST['name'] != $this->session->userdata('name') && $_POST['phone'] != $this->session->userdata('phone') ):
				date_default_timezone_set("PRC");
				$_POST['addtime'] = date("Y-m-j H:i:s");
				$_POST['ip'] = $this->input->ip_address();
				$this->db->insert('survey', $_POST);
				echo '<script type="text/javascript" language="javascript" charset="utf-8">alert("报名成功，活动开始时间为2012年4月7日，截至时间为2012年4月21日，期待您的参与！");location.href="/";</script>';
				//插入session
				$newdata = array(
					'name'		=> $_POST['name'],
					'phone'		=> $_POST['phone']
				);
				$this->session->set_userdata($newdata);
			else:
				echo '<script type="text/javascript" language="javascript" charset="utf-8">alert("您已报名成功，请勿重复报名！");location.href="/";</script>';
			endif;
		endif;
		//redirect('/');
	}
}